package com.sky.controller.user;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userShopController")
@RequestMapping("/user/shop")
@Api(tags = "用户端店铺管理")
@Slf4j
public class ShopController {
    public static final String KEY = "SHOP_STATUS";

    @Autowired
    private StringRedisTemplate redisTemplate;


    /**
     * 获取店铺营业状态
     *
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("获取店铺营业状态")
    public Result<Integer> shopGetStatus() {
        String s = redisTemplate.opsForValue().get(KEY);
        List<Integer> integers = JSONArray.parseArray("["+ s+ "]", Integer.class);
        log.info("获取店铺营业状态：{}", integers.get(0)== 1 ? "营业中" : "打烊中");
        return Result.success(integers.get(0));
    }
}
